package com.tec.security.controller;

import com.tec.security.service.ViewsIPService;
import com.tec.security.service.ViewsService;
import com.tec.security.service.NewsService;
import com.tec.security.utils.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@Api(tags = "网站首页接口")
@RequestMapping("/WWW")
public class WWWController {
    private final ViewsService homeViewsServices;
    private final NewsService adminnewsService;
    private final ViewsIPService viewsIPService;

    @Autowired
    public WWWController(ViewsService homeViewsServices, NewsService adminnewsService, ViewsIPService viewsIPService) {
        this.homeViewsServices = homeViewsServices;
        this.adminnewsService = adminnewsService;
        this.viewsIPService = viewsIPService;
    }

    /**
     * @description 所有uv访问量接口
     * @author 陆林
     * @date 2023-11-9
     */
    @ApiOperation(value = "所有uv访问量")
    @PostMapping("/allUV")
    public Result allViews() {
        int result = homeViewsServices.allHomeViews();
        Map<String, Object> map = new HashMap<>();
        map.put("allViews", result);
        return Result.success("请求成功", map);
    }

    /**
     * @description 今日uv访问量接口
     * @author 陆林
     * @date 2023-11-9
     */
    @ApiOperation(value = "今日uv访问量接口")
    @PostMapping("/todayUV")
    public Result todayViews() {
        int result = homeViewsServices.todayHomeViews();
        Map<String, Object> map = new HashMap<>();
        map.put("todayViews", result);
        return Result.success("请求成功", map);
    }

    /**
     * @description 单篇新闻uv访问量接口
     * @author 陆林
     * @date 2023-11-9
     */
    @ApiOperation(value = "单篇新闻uv访问量接口")
    @PostMapping("/newsViews")
    public Result views(Integer id) {
        return Result.success("请求成功", adminnewsService.views(id));
    }

    /**
     * @description 网站单篇新闻详情
     * @author 陆林
     * @date 2023-11-9
     */
    @ApiOperation(value = "网站单篇新闻详情")
    @PostMapping("/OneNews")
    public Result OneNews(Integer id) {
        return Result.success("请求成功", adminnewsService.NewsSelectOneByID(id));
    }

    /**
     * @description 首页三篇新闻详情
     * @author 陆林
     * @date 2023-11-9
     */
    @ApiOperation(value = "首页三篇新闻详情")
    @PostMapping("/ThreeNews")
    public Result ThreeNews() {
        return Result.success("请求成功", adminnewsService.newsSelectThree_Home());
    }

    /**
     * @description 网站新闻列表
     * @author 陆林
     * @date 2023-11-17
     */
    @ApiOperation(value = "网站新闻列表")
    @PostMapping("/NewsList")
    public Result NewsListAudit() {
        return Result.success("请求成功", adminnewsService.newsListAudit());
    }

    /**
     * @description 所有pv访问量接口
     * @author 陆林
     * @date 2023-11-9
     */
    @ApiOperation(value = "所有pv访问量")
    @PostMapping("/allPV")
    public Result allIPViews() {
        Map<String, Object> map = new HashMap<>();
        map.put("all", viewsIPService.allIP());
        return Result.success("请求成功", map);
    }

    /**
     * @description 今日pv访问量接口
     * @author 陆林
     * @date 2023-11-9
     */
    @ApiOperation(value = "今日pv访问量")
    @PostMapping("/todayPV")
    public Result todayViews(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        map.put("today", viewsIPService.todayIP(request));
        return Result.success("请求成功", map);
    }
}